package com.zhangxi.dao;

import com.zhangxi.javabean.Customer;
import com.zhangxi.util.BaseDao;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: CustomerDao
 * Package: com.zhangxi.dao
 */
public class CustomerDao extends BaseDao {
    /**
     * 用途：查询数据库返回所有客户对象
     * 返回：集合
     */
    public List<Customer> listCustomer() throws Exception {
        ArrayList<Customer> list = query(Customer.class, "select * from t_customer");
        return list;
    }

    public void insertCustomer(Customer customer) throws Exception {
        int row = update("insert into t_customer(id,NAME,gender,age,salary,phone) values (?,?,?,?,?,?);",
                customer.getId(), customer.getName(), customer.getGender(), customer.getAge(), customer.getSalary(), customer.getPhone());
    }

    public int updateCustomer(Customer customer) throws Exception {
        return update("update t_customer set name = ? , gender = ? , age = ? ," +
                        "salary = ? , phone = ? where id = ? ;", customer.getName(), customer.getGender(),
                customer.getAge(), customer.getSalary(), customer.getPhone(), customer.getId());
    }

    public int deleteCustomer(int id) throws Exception {
        return update("delete from t_customer where id =?", id);
    }
}
